package com.fixme4trade.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

public class FileUploader {

	public static void saveFile(String filePath, FileUploadEvent event) throws IOException {		

		UploadedFile arq = event.getFile();

		InputStream in = new BufferedInputStream(arq.getInputstream());
		
		File file = new File(filePath);		

		FileOutputStream fout = new FileOutputStream(file);

		while (in.available() != 0) {

			fout.write(in.read());

		}

		fout.close();
	}

}
